﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThinkGeo.MapSuite.WebEdition;
using ThinkGeo.MapSuite.Core;
namespace SensorNetworkUI
{
    public partial class AddUser : System.Web.UI.Page
    {

        SensorStructure sensor = new SensorStructure();


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
                Map1.CurrentExtent = new RectangleShape(-131.22, 55.05, -54.03, 16.91);
                Map1.MapUnit = GeographyUnit.DecimalDegree;
                  Map1.MapTools.OverlaySwitcher.Enabled = true;  
                 Map1.MapTools.MouseCoordinate.Enabled = true;
                 GoogleOverlay google = new GoogleOverlay("Google Map");
                 google.JavaScriptLibraryUri = new Uri(@"http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAoxK_HcqphMsnUQHEwLwHlRSavkNJi0NVTgm4UDidoiIU5dUJpRQW88FufPCp0aTPraxZgZFAIUHn3Q");
                 google.GoogleMapType = GoogleMapType.Normal;
                

                WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay();
                Map1.CustomOverlays.Add(worldMapKitOverlay);
              //  Map1.CustomOverlays.Add(google);
                // markerOverlay.Features.Add("Kansas", new Feature(-94.558, 39.078));


                ContextMenu onmap = new ContextMenu();
                ContextMenuItem pos = new ContextMenuItem("Add Sensor Here");
                pos.Click += new EventHandler<ContextMenuItemClickEventArgs>(showpos);
                onmap.MenuItems.Add(pos);

                Map1.ContextMenu = onmap;
                TextBox2.Attributes["onclick"] = "showMap(this.id)";

                //Map1. += new EventHandler<MapClickedEventArgs>(Map1_DoubleClick);
              

                

            }
 
        }

        void Map1_DoubleClick(object sender, MapClickedEventArgs e)
        {
   
        }
        private void showpos(object sender, ContextMenuItemClickEventArgs e)
        {
          //  this.Page.Title = e.Location.X.ToString();

            this.sensor = new SensorStructure();
            sensor.Longitude = e.Location.X;
            sensor.Lattitude = e.Location.Y;
            this.TextBox2.Text = sensor.Longitude + "," + sensor.Lattitude;
            
        }

        protected void TextBox2_TextChanged(object sender, EventArgs e)
        {

            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SensorStructure sens = new SensorStructure();
            sens.Id =int.Parse( DropDownList1.SelectedValue);


            string[] latlon = TextBox2.Text.Split(',');
            sensor.Lattitude = Double.Parse(latlon[1]);
            sensor.Longitude = Double.Parse(latlon[0]);


            sens.UpdateLocation();
        }
    }
}